package com.oscar.ehome.provider.videoPlay;

/**
 * Created by xielinke on 2017/7/22.
 */

public class NiceVideoPlayerManagers {
    private NiceVideoPlayers mVideoPlayer;
    private static NiceVideoPlayerManagers sInstance;

    private NiceVideoPlayerManagers() {
    }

    public static synchronized NiceVideoPlayerManagers instance() {
        if (sInstance == null) {
            sInstance = new NiceVideoPlayerManagers();
        }

        return sInstance;
    }

    public NiceVideoPlayers getCurrentNiceVideoPlayer() {
        return this.mVideoPlayer;
    }

    public void setCurrentNiceVideoPlayer(NiceVideoPlayers videoPlayer) {
        if (this.mVideoPlayer != videoPlayer) {
            this.releaseNiceVideoPlayer();
            this.mVideoPlayer = videoPlayer;
        }

    }

    public void suspendNiceVideoPlayer() {
        if (this.mVideoPlayer != null && (this.mVideoPlayer.isPlaying() || this.mVideoPlayer.isBufferingPlaying())) {
            this.mVideoPlayer.pause();
        }

    }

    public void resumeNiceVideoPlayer() {
        if (this.mVideoPlayer != null && (this.mVideoPlayer.isPaused() || this.mVideoPlayer.isBufferingPaused())) {
            this.mVideoPlayer.restart();
        }
    }

    public void startNiceVideoPlayer() {
        if (this.mVideoPlayer != null) {
            this.mVideoPlayer.start(0);
        }
    }

    public void releaseNiceVideoPlayer() {
        if (this.mVideoPlayer != null) {
            this.mVideoPlayer.release();
            this.mVideoPlayer = null;
        }

    }

    public boolean onBackPressd() {
        if (this.mVideoPlayer != null) {
            if (this.mVideoPlayer.isFullScreen()) {
                return this.mVideoPlayer.exitFullScreen();
            }

            if (this.mVideoPlayer.isTinyWindow()) {
                return this.mVideoPlayer.exitTinyWindow();
            }
        }

        return false;
    }
}

